/*
 * Copyright (C), 2002-2016, 苏宁易购电子商务有限公司
 * FileName: TaskA.java
 * Author:   15050536
 * Date:     2016年12月7日 下午4:55:47
 * Description: //模块目的、功能描述      
 * History: //修改记录
 * <author>      <time>      <version>    <desc>
 * 修改人姓名             修改时间            版本号                  描述
 */
package com.suning.sawp.service.impl.tm;

import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.Callable;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import com.suning.sawp.constants.PromSysConstants;
import com.suning.sawp.dto.common.ReturnMsg;
import com.suning.sawp.dto.promotion.InnerCouponDetail;
import com.suning.sawp.intf.promotion.InnerCouponService;
import com.suning.sawp.intf.tm.vo.CouponInfoVo;


/**
 * 查询券信息 任务
 *
 * @author 15050536 石键平
 */
public class TaskG implements Callable<CouponInfoVo>{

	private InnerCouponService innerCouponService;
	
	private String employeeId;
	
	public TaskG(InnerCouponService innerCouponService,String employeeId){
		this.innerCouponService	= innerCouponService;
		this.employeeId = employeeId;
	}
	
	@Override
	public CouponInfoVo call() throws Exception {
		CouponInfoVo couponInfo = new CouponInfoVo();
		ReturnMsg<List<InnerCouponDetail>> returnMsg = innerCouponService.queryCouponListByStaffIdAndTrigerId(employeeId, PromSysConstants.BONUS_WEIXIN_TM_PROMOTION);
		if(StringUtils.isNotEmpty(returnMsg.getErrorMessage())){
			couponInfo.setErrorMag(returnMsg.getErrorMessage());
		}else{
			List<InnerCouponDetail> list = returnMsg.getData();
			if(CollectionUtils.isEmpty(list)){
				return couponInfo;
			}
			//为时光机特意造的券，也就一条。故直接取get(0);
			InnerCouponDetail coupon = list.get(0);
			couponInfo.setName(coupon.getActivityName());
			couponInfo.setRule(coupon.getCouponRule());
			String price = coupon.getCouponValue();
			couponInfo.setPrice(String.valueOf(new BigDecimal(price).intValue()));
			couponInfo.setActivityId(coupon.getActivityId());
			couponInfo.setSecurityKey(coupon.getSecurityKey());
		}
		return couponInfo;
	}
}
